<?php  
$file_name = $year."年".$month."月入驻企业统计报表";

?>
<?php if(empty($report)){?>
<div class="right_side_operate_area">
	<div class="right_side_title left">
		<h2><?php echo $file_name;?></h2>
	</div>
    <?php
    	$url_explode=explode("group=", $_SERVER["QUERY_STRING"]);
    	echo '<div class="right back_btn">';
		echo $html->link("导出报表","/reports/compdatareport/1?year=".$year."&month=".$month."&group=".$url_explode[1]);
		echo '</div>';
	?> 
	<div class="term_choose_area right">
    	<div class="screen_list" id="screen_list" style="display:none;visibility:hidden;">
    	</div>
    </div>
    <div class="form_sx_drop right">
    	<?php 
		 $user=$session->read('User');
		 if($user['isadmin']||$user['isvisitor']){
			$grouplist=array_merge(array(""=>"请选择模块"),$grouplist);
	    	echo $form->select('ddlgroup',$grouplist,$group_mod_id, null,null);
			 }
    		$years=$str->getafteryear(0);
    		echo $form->select('ddlyear',$years, $year, null,null);
		    echo $form->select('ddlmonth',$months, $month, null,null);
		?>
	</div>
    <div class="clear"></div>
</div>
<?php }?>
<style>
.items_list table{
	color:black;
	font-size:12px;
	line-height:25px;
	text-align:center;
	border-collapse:collapse;
	border-style:solid;
	border-bottom:2px solid ;
}

.items_list table tr th{
	border-left:1px solid ;
	border-top:1px solid ;
	border-right:1px solid ;
	border-bottom:1px solid ;
}
.items_list table tr td{
	border-left:1px solid ;
	border-top:1px solid ;
	border-right:1px solid ;
	border-bottom:1px solid ;
}
.items_list table tr .th{
	border-left:2px solid ;
	border-top:2px solid ;
	border-right:2px solid ;
}

.items_list table tr .lth{
	border-left:2px solid ;
}

.items_list table tr .rth{
	border-right:2px solid ;
}
</style>

<div class="right_side_scollbar">
    <div class="detail_info_panel">
        <div class="items_list">
        	<table border="1">
        	<?php 
        		if(!empty($report)){
        			echo "<tr><td colspan='13' align='center' style='font-size:18px'><b>".$year."年".$month."月常熟国家大学科技园入驻企业统计报表</b></td></tr>";
        		}
        	?>
            	<tr>
            		<th class="th" rowspan="2" >序号</th>
                    <th class="th" rowspan="2">企业名称</th>
                    <th class="th" rowspan="2">模块</th>
		 			<th class="th" colspan="2">总收入</th>
		 			<th class="th" colspan="2">利税总和</th>
		 			<th class="th" colspan="2">利润总额</th>
		 			<th class="th" colspan="3">科技产出</th>
		 			<th class="th" rowspan="2">项目性质</th>
		 			<th class="th" rowspan="2">载体位置</th>
                </tr>
                <tr>
		 			<th class="lth">累计（万元）</th>
		 			<th>同比（%）</th>
		 			<th class="lth">累计（万元）</th>
		 			<th>同比（%）</th>
		 			<th class="lth">累计（万元）</th>
		 			<th>同比（%）</th>
		 			<th class="lth">专利数（件）</th>
		 			<th >高新产品（件）</th>
		 			<th>软件产品（件）</th>
		 		</tr>
		 		<?php 
		 		//print_r($compdatas);
		 		//echo "......................................";
		 		if($compdatas){
		 			for($i=0; $i<count($compdatas); $i++){
		 				$cid = $compdatas[$i]["companies"]["id"];
		 				$patent = $str->getPatents($year,$month,$cid);
		 				$ht_pro = $str->getProducts($year,$month,$cid,$ht_cvid,$successDeclareId);
		 				$sw_pro = $str->getProducts($year,$month,$cid,$sw_cvid,$successDeclareId);
		 				echo '<tr>';
		 				echo '<td class="lth">'.($i+1).'</td>';
		 				echo '<td class="lth">'.$compdatas[$i]["companies"]["company_name"].'</td>';
		 				echo '<td class="lth">'.$grouplist[$compdatas[$i]["companies"]["groupid"]].'</td>';
		 				echo '<td class="lth">'.$str->formatquantity($compdatas[$i]["OUTEC"]["income"]).'</td>';
		 				if(!empty($last_compdatas)){
			 				if(empty($last_compdatas[$i]["OUTEC"]["income"]) || $last_compdatas[$i]["OUTEC"]["income"]== 0 ){
				 				if(!empty($compdatas[$i]["OUTEC"]["income"]) && $compdatas[$i]["OUTEC"]["income"] != 0){
				 					echo '<td>100</td>';
			 					}else{
			 						echo '<td>-</td>';
			 					}
			 				}else{
			 					if(empty($compdatas) || empty($compdatas[$i]["OUTEC"]["income"]) || $compdatas[$i]["OUTEC"]["income"] == 0 ){
			 						echo '<td>-100</td>';
			 					}else{
				 					$income_data = ($compdatas[$i]["OUTEC"]["income"]-$last_compdatas[$i]["OUTEC"]["income"])/$last_compdatas[$i]["OUTEC"]["income"]*100;
				 					echo '<td>'.$str->setIntPercent($income_data).'</td>';
			 					}
			 				}
		 				}else{
		 					if(!empty($compdatas[$i]["OUTEC"]["income"]) && $compdatas[$i]["OUTEC"]["income"] != 0){
		 						echo '<td>100</td>';
		 					}else{
		 						echo '<td>-</td>';
		 					}
		 				}
		 				echo '<td class="lth">'.$str->formatquantity($compdatas[$i]["OUTEC"]["tax"]).'</td>';
		 				if(!empty($last_compdatas)){
			 				if(empty($last_compdatas[$i]["OUTEC"]["tax"]) || $last_compdatas[$i]["OUTEC"]["tax"] == 0){
			 					if(!empty($compdatas[$i]["OUTEC"]["tax"])&& $compdatas[$i]["OUTEC"]["tax"] != 0){
			 						echo '<td>100</td>';
			 					}else{
			 						echo '<td>-</td>';
			 					}
			 				}else{
			 					if(empty($compdatas) || empty($compdatas[$i]["OUTEC"]["tax"]) || $compdatas[$i]["OUTEC"]["tax"] == 0 ){
			 						echo '<td>-100</td>';
			 					}else{
				 					$tax_data = ($compdatas[$i]["OUTEC"]["tax"]-$last_compdatas[$i]["OUTEC"]["tax"])/$last_compdatas[$i]["OUTEC"]["tax"]*100;
			 						echo '<td>'.$str->setIntPercent($tax_data).'</td>';
			 					}
			 				}
			 			}else{
			 				if(!empty($compdatas[$i]["OUTEC"]["tax"])&& $compdatas[$i]["OUTEC"]["tax"] != 0){
		 						echo '<td>100</td>';
		 					}else{
		 						echo '<td>-</td>';
		 					}
		 				}
		 				echo '<td class="lth">'.$str->formatquantity($compdatas[$i]["OUTEC"]["profit"]).'</td>';
//		 				debug($last_compdatas[$i]["OUTEC"]["profit"]);
//		 				debug($compdatas[$i]["OUTEC"]["profit"]);
//		 				debug($last_compdatas[$i]["OUTEC"]["profit"] == '0.00');
//		 				debug(!empty($compdatas[$i]["OUTEC"]["profit"]));
		 				if(!empty($last_compdatas)){
			 				if(empty($last_compdatas[$i]["OUTEC"]["profit"]) || $last_compdatas[$i]["OUTEC"]["profit"] == 0){
				 				if(!empty($compdatas[$i]["OUTEC"]["profit"]) && $compdatas[$i]["OUTEC"]["profit"] != 0){
			 						echo '<td>100</td>';
			 					}else{
			 						echo '<td>-</td>';
			 					}
			 				}else{
			 					if(empty($compdatas) || empty($compdatas[$i]["OUTEC"]["profit"]) || $compdatas[$i]["OUTEC"]["profit"] == 0 ){
			 						echo '<td>-100</td>';
			 					}else{
			 						$profit_data = ($compdatas[$i]["OUTEC"]["profit"]-$last_compdatas[$i]["OUTEC"]["profit"])/$last_compdatas[$i]["OUTEC"]["profit"]*100;
			 						echo '<td>'.$str->setIntPercent($profit_data).'</td>';
			 					}
			 				}
		 				}else{
		 					if(!empty($compdatas[$i]["OUTEC"]["profit"]) && $compdatas[$i]["OUTEC"]["profit"] != 0){
		 						echo '<td>100</td>';
		 					}else{
		 						echo '<td>-</td>';
		 					}
		 				}
		 				echo '<td class="lth">'.$str->formatquantity($patent).'</td>';
		 				echo '<td>'.$str->formatquantity($ht_pro).'</td>';
		 				echo '<td>'.$str->formatquantity($sw_pro).'</td>';
		 				$declares = $str->getDeclareType($cid,$successDeclareId);
		 				$u_declares = array();
		 				$comp_declare = "";
		 				if(!empty($declares)){
			 				foreach($declares as $declare){
			 					$u_declares[] = $declare["CompTalent"]["type_id"];
			 				}
			 				$u_declares = array_unique($u_declares);
			 				foreach($u_declares as $u_declare){
			 					$comp_declare .= $declaretype[$u_declare].",";
			 				}
			 				//print_r($comp_declare);
			 				$comp_declare = rtrim($comp_declare,",");
		 				}
		 				if(empty($comp_declare)){
		 					$comp_declare = "-";
		 				}
		 				echo '<td class="lth">'.$comp_declare.'</td>';
		 				echo '<td class="lth rth">';
		 				$comp_carriers = $str->getCarrier($cid);
		 				if(!empty($comp_carriers)){
		 					$carr = "";
		 					foreach ($comp_carriers as $carrier){
		 						$forb = $carrier['CompCarrierlease']['forbid'];
		 						if(empty($forb)){
		 							$forbid = "";
		 						}else{
		 							$forbid = $forbids[$forb]."，";
		 						}
		 						$carr = $forbid.$carrier['CompCarrierlease']['location']."</br>";
		 					}
		 					$carr = rtrim($carr,"</br>");
		 					echo $carr;
		 				}else{
		 					echo "-";
		 				}
		 				echo'</td>';
		 				echo '</tr>';
		 		}
		 	}?>
            </table>
		</div>
    </div>
</div>

<script>
var webpath=$("#getpath").attr('href');
var urlpath=webpath+"reports/compdatareport/?seach=all";
$(document).ready(function(){
	$("#ddlgroup").change(function(){
		searchproject();
		});	
	$("#ddlyear").change(function() {  
		searchproject();
	});
	$("#ddlmonth").change(function(){
		searchproject();
	});
});
function searchproject()
{
	var group=$("#ddlgroup").val();	
	var year = $("#ddlyear").val();
	var month = $("#ddlmonth").val();
	
	if(group==""&& year=="" && month==""){
		window.location.href=urlpath;
	}else{
		if(group!=""){
			urlpath+="&group="+group;
			}
		if(year.trim() != ""){
			urlpath+="&year="+year.trim();
		}
		if(month.trim() != ""){
			urlpath+="&month="+month.trim();
		}
		window.location.href=urlpath;
	}
	return false;
}
</script>